import com.alibaba.fastjson.JSONObject;
import com.weaverboot.frame.ioc.anno.classAnno.WeaIocReplaceComponent;
import com.weaverboot.frame.ioc.anno.methodAnno.WeaReplaceAfter;
import com.weaverboot.frame.ioc.handler.replace.weaReplaceParam.impl.WeaAfterReplaceParam;
import com.weaverboot.tools.componentTools.table.WeaTableTools;
import com.weaverboot.tools.logTools.LogTools;
import com.weaverboot.weaComponent.impl.weaForm.impl.BrowserWeaForm;
import com.weaverboot.weaComponent.impl.weaForm.impl.UploadWeaForm;
import com.weaverboot.weaComponent.impl.weaForm.inte.AbstractWeaForm;
import com.weaverboot.weaComponent.impl.weaTable.column.impl.DefaultWeaTableColumn;
import com.weaverboot.weaComponent.impl.weaTable.table.impl.DefaultWeaTable;

@WeaIocReplaceComponent
public class ReplaceWeaTable {
    @WeaReplaceAfter(value = "/api/workflow/reqlist/splitPageKey",order = 1)
    public String replace(WeaAfterReplaceParam weaAfterReplaceParam){
        //将接口返回报文反序列化成jsonobject对象
        JSONObject jsonObject = JSONObject.parseObject(weaAfterReplaceParam.getData());
        //获取到接口报文中的sessionkey
        String sessionkey = jsonObject.getString("sessionkey");
        try {
            //因为待办事宜表格为标准表格，所以我们用defaultWeaTable来获取
            //在整个拦截过程中，WeaTableTools是一个非常关键的工具类
            //此处是根据sessionkey，反序列化表格类
            DefaultWeaTable defaultWeaTable = WeaTableTools.checkTableStringConfig(sessionkey,DefaultWeaTable.class);
            //找到table中名为创建者的列，并用字段默认实现类DefaultWeaTableColumn去获取
            DefaultWeaTableColumn defaultWeaTableColumn = defaultWeaTable.readWeaTableColumnWithColumn("创建者", DefaultWeaTableColumn.class);
            //将此类的列名修改为操作人员
            defaultWeaTableColumn.setText("操作人员");
            //将修改后的table，以sessionkey最为键值，覆盖原来缓存中的table数据
            WeaTableTools.setTableStringVal(sessionkey,WeaTableTools.toTableString(defaultWeaTable));
        } catch (Exception e) {
            LogTools.error("发生错误，原因为:" + e.getMessage());
        }

        BrowserWeaForm browserWeaForm = new BrowserWeaForm();
        UploadWeaForm uploadWeaForm = new UploadWeaForm();


        //将原有接口报文返回
        return weaAfterReplaceParam.getData();
    }
}
